$(function(){
    init_Aistaff();
});
/**初始化部门列表*/
function init_Aistaff(){
    $.post(ctx+"dept/getUseeAndDepttree",{},function (r) {
        var array  = r.msg;
        $("#using_json").jstree({
            "core": {
                "multiple": false,//单选
                "data":array
            },
            "checkbox" : {
                "keep_selected_style" : false
            },
            "plugins" : [ "wholerow", "checkbox" ]
        });
        // 获得点击节点的id
        $('#using_json').on("changed.jstree", function (e, data) {
            var nodeid = data.node.id;
            var text = data.node.text;
            var label = "<div class='label label-danger p-3 m-3 pull-left' data-id='"+nodeid+"'>"+text+"</div>";
            $("#user-selectfor").empty().append(label);
        });
    });
}

/**点击分配确定 分配客户的跟踪人员**/
function aiDisfenpei() {
    /**记录分配的数据id**/
    var ids = $("#bigDisTable").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要分配的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].aiId;
        if (i !== (ids.length - 1)) ids_arr += ",";
    }
    /**记录分配的人员**/
    var useridsArray = new Array();
    $("#user-selectfor").find("div").each(function () {
        var notselect = $(this).attr("data-id");
        useridsArray.push(notselect);
    });
    if (!useridsArray.length) {$JuXue.n_warning("请选择需要分配的用户信息！");return;}
    var bpDistribute = useridsArray.join(",");
    //分配完成 用户自动进入新入库阶段
    $.post(ctx+"aiEpResoure/bigEmpbatchUpdateByEmp",{ids:ids_arr,aiDistriute:bpDistribute,aiStage:"1"},function (r) {
        if (r.code == 0){
            $JuXue.n_success("分配成功");
            $("#bigDisModal").modal("hide");
            $JuXue.refreshTable("bigDisTable");
            $(".theme-panel").removeClass("active");
            $("#selectTheme").hide();
        }else{$JuXue.n_warning(r.msg);}
    });
}

